/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package util.www.sql;

import java.sql.SQLException;

/**
 *
 * @author Rdelacruz
 */
@Deprecated
public class WhereSqlEstaticoCond 
extends WhereSqlCond
{
            
    
    
    public boolean agregarInt(String columna, int valor) throws SQLException {       
        return agregar(columna,valor+"",false);
    }
    
    public boolean agregarStringInt(String columna, String valor) throws SQLException {       
        return agregar(columna,valor,false);
    }
    
    public boolean agregarString(String columna, String valor) throws SQLException {       
        return agregar(columna,valor,true);
    }
    
    public boolean agregarString(String columna, String[] valores) throws SQLException {       
        if(valores.length>0) {
            StringBuilder sb = new StringBuilder();
            sb.append("(");
            for(String v:valores) {
                sb.append("'");
                sb.append(v);
                sb.append("'");
                sb.append(",");
            }            
            sb.deleteCharAt(sb.length()-1);//borrando ultima coma
            sb.append(")");
            
            condiciones.add(columna+" in "+sb.toString());
            return true;
        }
        return false;
    }
    
    protected final boolean agregar(String columna, String valor, boolean valorEntreComillas) throws SQLException {       
        if(valor==null || valor.trim().isEmpty()) {
            siNoValidaAgregar(columna);
            return false;
        }
        else {        
            if(valorEntreComillas)
                condiciones.add(columna+" = '"+ valor +"'");
            else
                condiciones.add(columna+" = "+ valor);
        }
        return true;
    }    
    
    protected void siNoValidaAgregar(String columna) throws SQLException {
        throw new SQLException("Columna '"+columna+"' no debe tener valor nulo o vacío");
    }
   
    
}
